package com.ndp.fb.creative.fetchdata.controller;

import com.ndp.fb.creative.fetchdata.model.param.ComeParam;
import com.ndp.fb.creative.fetchdata.model.vo.SumResultVo;
import com.ndp.fb.creative.fetchdata.service.AccountImagesService;
import com.ndp.fb.creative.fetchdata.util.ResponseUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by evan.wan on 2015/5/21.
 */
@Controller
@RequestMapping("/data")
public class HashCodeController {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    AccountImagesService accountImagesService;


    @RequestMapping("/get")
    //@ResponseBody
    public String getData(Map<String, Object> model, ComeParam param) {
        logger.info("HashCodeController getData():"+param.getName()+"------------------"+param.getFbUrl());
        model.put("time", new Date());
        model.put("vo", accountImagesService.getHashCodeByName(param.getName()));
        return "welcome";
    }

    @RequestMapping("/fetch")
    @ResponseBody
    public ResponseEntity<Object> fetchData(ComeParam param) {
        logger.info("HashCodeController fetchData():" + param.getName() + "------------------" + param.getType());
        List<SumResultVo> res;
        if(param.getType() != null && "name".equals(param.getType()))
        {
            res = accountImagesService.getHashCodeByNames(param.getName());
        }
        else if (param.getType() != null && "hash".equals(param.getType()))
        {
            res = accountImagesService.getHashCodeByHashs(param.getName());
        }
        else
        {
            res = new ArrayList<>();
        }

        return ResponseUtils.ok(res);
    }


}
